package cc.wanforme.chipmunity.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cc.wanforme.chipmunity.common.bean.WebResponse;
import cc.wanforme.chipmunity.system.po.user.User;
import cc.wanforme.chipmunity.system.service.interfaces.UserService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/** 登录、注册、注销
 * @author wanne
 * 2019年8月3日
 * 
 */
@Controller
public class RegisterController {
	private static final Logger log = LoggerFactory.getLogger(RegisterController.class);
	
	
	@Autowired
	private UserService userService;
	
	@RequestMapping("/register")
	@ResponseBody
	@ApiOperation("注册")
	@ApiImplicitParams({
		@ApiImplicitParam(name="user", dataType="User", value="注册的用户信息，用户名和密码", required=true),
		@ApiImplicitParam(name="password", dataType="String", value="确认密码", required=true)
	})
	public WebResponse register(@RequestBody(required=true) User user, @RequestParam(required=true) String password) {
		try {
			return userService.saveUser(user, password);
		} catch (Exception e) {
			log.error("注册失败："+user);
			log.error("注册", e);
			return WebResponse.fail("出现异常");
		}
	}
	
}
